<template>
  <view class="container">
    <view class="example" style="width: 100%;height: 100%;border-radius: 1%;background-color: #eeeeee">
      <uni-forms ref="form" :model="this.shop" labelWidth="80px">
        <uni-forms-item class="item1" name="shopsId" hidden>
          <uni-easyinput v-model="shop.shopsId"    hidden/>
        </uni-forms-item>
        <uni-forms-item class="item1" label="店铺名称" name="shopName">
          <uni-easyinput v-model="shop.shopName" placeholder="请输入店铺名称"   />
        </uni-forms-item>
        <uni-forms-item class="item1" label="上传logo" name="shopLogo">
          <img class="item2" @click="chooseImage()" :src="shop.shopLogo"   />
        </uni-forms-item>
        <uni-forms-item class="item1" label="主要产品" name="mainProducts">
          <uni-easyinput v-model="shop.mainProducts" placeholder="请输入主要产品"   />
        </uni-forms-item>
        <uni-forms-item class="item1" label="店铺地址" name="shopUrl">
          <uni-easyinput v-model="shop.shopUrl" placeholder="请输入店铺地址"   />
        </uni-forms-item>
        <uni-forms-item class="item1" label="详细地址" name="shopAddress">
          <uni-easyinput v-model="shop.shopAddress" placeholder="请输入详细地址"   />
        </uni-forms-item>
        <uni-forms-item class="item1" label="店铺简介" name="shopIntroduction">
          <uni-easyinput v-model="shop.shopIntroduction" placeholder="请输入店铺简介"   />
        </uni-forms-item>
        <uni-forms-item class="item1" label="店铺描述" name="shopDescription">
          <uni-easyinput v-model="shop.shopDescription" placeholder="请输入店铺描述"   />
        </uni-forms-item>
        <uni-forms-item class="item1" label="店铺联系电话" name="corporatePhone">
          <uni-easyinput v-model="shop.shopPhone" placeholder="请输入店铺联系电话"   />
        </uni-forms-item>
      </uni-forms>
      <button type="primary"  @click="submit"  >提交</button>
    </view>
  </view>
</template>

<script>
import {uploadAvatar, submitshop , getMarketersProfile} from "@/api/system/marketers"
import {getshopDetailProfile} from "../../api/system/marketers";

export default {
  data() {
    return {
      images: "",
      /*商家信息*/
      Echo: "1",
      shop: {
        shopsId: "",
        shopName: "",
        shopUser: "",
        shopLogo: "",
        shopUrl: "",
        shopAddress: "",
        shopType: "",
        shopStatus: "",
        isSelf: "",
        shopPhone: "",
        shopEmail: "",
        shopApprovedAt: "",
        applyId: "",
        orderId: "",
        openingHours: "",
        shopLicense: "",
        shopSize: "",
        mainProducts: "",
        otherProducts: "",
        shopApprovedBy: "",
        shopDescription: "",
        shopFacade: "",
        shopIntroduction: "",
        createTime: "",
        updateTime: "",
        bankAccountName: "",
        bankAccount: "",
        subBranch: "",
        lineNumber: "",
        legalPersonName: "",
        legalPersonDocument: "",
        legalPersonImage: "",
        corporateName: "",
        corporatePhone: "",
        corporateUrl: "",
        corporateAddress: "",
        corporateCount: "",
        registeredCapita: "",
        contactName: "",
        contactPhone: "",
        contactEmail: "",
        licenseNumber: "",
        businessScope: "",
        shopELicense: "",
        rejectReason: ""
      },
      marketers: {
        applyId: "",
        shopName: "",
        shopLogo: "",
        shopUser: "",
        mainProducts: "",
        shopUrl: "",
        shopAddress: "",
        shopIntroduction: "",
        bankAccountName: "",
        bankAccount: "",
        subBranch: "",
        lineNumber: "",
        legalPersonName: "",
        legalPersonDocument: "",
        legalPersonImage: "",
        corporateName: "",
        corporateUrl: "",
        corporateAddress: "",
        corporateCount: "",
        corporatePhone: "",
        registeredCapital: "",
        contactName: "",
        contactPhone: "",
        contactEmail: "",
        licenseNumber: "",
        businessScope: "",
        shopELicense: "",
        status: ""
      },
      sexs: [
        {
          text: '未审核',
          value: "0"
        }, {
          text: '未通过',
          value: "1"
        },
        {
          text: '通过',
          value: "2"
        }],
      rules: {
        nickName: {
          rules: [{
            required: true,
            errorMessage: '用户昵称不能为空'
          }]
        },
        phonenumber: {
          rules: [{
            required: true,
            errorMessage: '手机号码不能为空'
          }, {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            errorMessage: '请输入正确的手机号码'
          }]
        },
        email: {
          rules: [{
            required: true,
            errorMessage: '邮箱地址不能为空'
          }, {
            format: 'email',
            errorMessage: '请输入正确的邮箱地址'
          }]
        }
      }
    }
  },
  onLoad() {
    //console.log(this.$store.query.shopsId)
    this.marketers.applyId = this.$store.state.user.userId;
    this.getMarketers(this.marketers.applyId)
    console.log(this.$route.query.shopsId+"+++++")
    if (this.$route.query.shopsId){
      this.getShopByShopsId(this.$route.query.shopsId)
    }
  },
  onReady() {
    this.$refs.form.setRules(this.rules)
  },
  methods: {
    getShopByShopsId(shopsId){
      console.log(JSON.stringify(this.$route.query.shopsId)+"y")
      getshopDetailProfile(shopsId).then(response => {
        console.log(JSON.stringify(response)+"=")
        if (response!=null){
          this.Echo = "2";
          this.shop = response

        }
      })
    },
    chooseImage() {
      uni.chooseImage({
        count: 1,
        sizeType: ['original', 'compressed'],
        sourceType: ['album'],
        success: (res) => {
            this.shop.shopLogo = res.tempFiles[0].path;
          let data = {name: 'file', filePath: this.marketers.shopLogo}
          uploadAvatar(data).then(response => {
            if (response.data!= {}){
              this.shop.shopLogo[0] = response.data.url
            }
          })
        },
        fail: (err) => {
          console.log(err.errMsg);
        }
      });
    },
    getMarketers(applyId) {
      //console.log(JSON.stringify(this.$store.query.shopUser)+"y")
      getMarketersProfile(applyId).then(response => {
        console.log(JSON.stringify(response+"a"))
        if (response.data!=null){
          this.Echo = "2";
          this.marketers = response.data
        }
      })
    },
    submit(ref) {
      this.shop.shopType = this.marketers.shopType
      this.shop.shopStatus = 0;
      this.shop.shopUser = this.$store.state.user.name
      this.shop.shopStatus = this.marketers.shopStatus
      this.shop.isSelf = this.marketers.isSelf
      this.shop.shopEmail = this.marketers.shopEmail
      this.shop.shopApprovedAt = this.marketers.shopApprovedAt
      this.shop.applyId = this.marketers.applyId
      this.shop.orderId = this.marketers.orderId
      this.shop.openingHours = this.marketers.openingHours
      this.shop.shopLicense = this.marketers.shopLicense
      this.shop.shopSize = this.marketers.shopSize
      this.shop.otherProducts = this.marketers.otherProducts
      this.shop.shopApprovedBy = this.marketers.shopApprovedBy
      this.shop.shopFacade = this.marketers.shopFacade
      this.shop.createTime = this.marketers.createTime
      this.shop.updateTime = this.marketers.updateTime
      this.shop.bankAccountName = this.marketers.bankAccountName
      this.shop.bankAccount = this.marketers.bankAccount
      this.shop.subBranch = this.marketers.subBranch
      this.shop.lineNumber = this.marketers.lineNumber
      this.shop.legalPersonName = this.marketers.legalPersonName
      this.shop.legalPersonDocument = this.marketers.legalPersonDocument
      this.shop.legalPersonImage = this.marketers.legalPersonImage
      this.shop.corporateName = this.marketers.corporateName
      this.shop.corporatePhone = this.marketers.corporatePhone
      this.shop.corporateUrl = this.marketers.corporateUrl
      this.shop.corporateAddress = this.marketers.corporateAddress
      this.shop.corporateCount = this.marketers.corporateCount
      this.shop.registeredCapita = this.marketers.registeredCapita
      this.shop.contactName = this.marketers.contactName
      this.shop.contactPhone = this.marketers.contactPhone
      this.shop.contactEmail = this.marketers.contactEmail
      this.shop.licenseNumber = this.marketers.licenseNumber
      this.shop.businessScope = this.marketers.businessScope
      this.shop.shopELicense = this.marketers.shopELicense
      this.shop.rejectReason = this.marketers.rejectReason
      this.$refs.form.validate().then(res => {
        submitshop(this.shop).then(response => {
          this.$modal.msgSuccess("添加成功")
          setTimeout(() => {
            this.$modal.close();
          }, 5000);
        })
      })
      uni.navigateBack();
    }
  }
}
</script>

<style lang="scss">
page {
  background-color: #ffffff;
}

.example {
  padding: 15px;
  background-color: #fff;
}

.segmented-control {
  margin-bottom: 15px;
}

.button-group {
  margin-top: 15px;
  display: flex;
  justify-content: space-around;
}

.form-item {
  display: flex;
  align-items: center;
  flex: 1;
}

.button {
  display: flex;
  align-items: center;
  height: 35px;
  line-height: 35px;
  margin-left: 10px;
}
.item1{
  /*width: 50%;*/
  /*margin-left: 30%;*/
}
.item2{

  width: 120px;
  height: 120px;
  /*margin-left: 50%;*/
  border: 1px solid;
}
.readonly{
  disable:true;
}
</style>
